package com.carlinfo.userscenter.users.service.impl;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.carlinfo.userscenter.users.dao.IARoleDao;
import com.carlinfo.userscenter.users.dao.impl.ARoleDaoImpl;
import com.carlinfo.userscenter.users.pojo.ARole;
import com.carlinfo.userscenter.users.service.IUsersService;

/**
 * ~usersService的实现类
 * 
 * @author JayLong
 *
 */
public class UsersServiceImpl implements IUsersService
{
	/**
	 * =左边是父类
	 * =右边是子类
	 * ~父类引用指向子类对象
	 */
	private IARoleDao roleDao = new ARoleDaoImpl();
	/*
	 * {
			//响应码 
			"code":"0",
			// 响应码的描述
			"info":"成功",
			"data":
			{
				// id 
				"id":"",
				//sql语句影响的条数 
				"effect":""
			}
		}
	 * */
	@Override
	public JSONObject saveOneRoleService(ARole role)
	{
		JSONObject resultJSON = new JSONObject();
		/* dao返回值指的是执行sql语句影响的条数 */
		int res = this.roleDao.saveOne(role);
		if(res > 0)
		{
			/* 添加成功 */
			JSONObject dataJSON = new JSONObject();
			/* 在json中,id是整数  */
			dataJSON.put("id", role.getId() + "");
			/* ""+任何类型,结果都是字符串类型 */
			dataJSON.put("effect", res + "");
			/* 将resultJSON和dataJSON关联起来 */
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code","0");
			resultJSON.put("info", "添加成功");
		}else
		{
			/* 添加失败 */
			resultJSON.put("code", "1");
			resultJSON.put("info", "添加失败");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneRoleService(ARole role)
	{
		return null;
	}

	@Override
	public JSONObject deleteOneRoleService(ARole role)
	{
		return null;
	}

	@Override
	public ARole findOneRoleService(Map<String, Object> condMap)
	{
		return this.roleDao.findOne(condMap);
	}

	@Override
	public List<ARole> findCondListRoleService(Map<String, Object> condMap)
	{
		return null;
	}

}
